package com.huawei.petapp2.search;


import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huawei.petapp2.R;
import com.huawei.petapp2.activity.widget.BaseListAdapter;
import com.huawei.petapp2.entity.ProductImgs;
import com.huawei.petapp2.entity.SearchBean;

import butterknife.BindView;

/**
 * 搜索商品Adapter
 */
public class SearchGoodsAdapter extends BaseListAdapter<SearchBean, SearchGoodsAdapter.ViewHolder> {

    private Context context;

    protected SearchGoodsAdapter(Context context) {
        this.context=context;
    }

    @Override
    protected int getItemViewLayout() {
        return R.layout.item_search_goods;
    }

    @Override
    protected ViewHolder getItemViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    class ViewHolder extends BaseListAdapter.ViewHolder {

        @BindView(R.id.image_goods)
        ImageView ivGoods;
        @BindView(R.id.text_goods_name)
        TextView tvName;
        @BindView(R.id.text_goods_price)
        TextView tvPrice;
        @BindView(R.id.text_market_price)
        TextView tvMarketPrice;

        private SearchBean mItem;

        ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void bind(int position) {
            mItem = getItem(position);
            tvName.setText(mItem.getProductName());
            String sellmoney="";
            String marketPrice=null;
            // 设置商场价格, 并添加删除线
            if(mItem.getProductSkus().size()>0)
            {
                sellmoney=String.valueOf(mItem.getProductSkus().get(0).getSellPrice());
                Integer.toString(mItem.getProductSkus().get(0).getOriginalPrice());
               /* SpannableString spannableString = new SpannableString(marketPrice);
                spannableString.setSpan(new StrikethroughSpan(), 0, marketPrice.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                tvMarketPrice.setText(spannableString);
*/
            }
            else
            {
                marketPrice="";
            }
            tvPrice.setText(sellmoney);
            tvMarketPrice.setText(marketPrice);
            ProductImgs picture = mItem.getProductImgs().get(0);
            Glide.with(context)
                    .load(picture.getUrl())
                    .into(ivGoods);
        }
    }

}
